package com.domainVO;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 大忽悠
 * @create 2022/2/10 14:22
 */
@ApiModel("封装分页信息")
@Data
public class PageInfoVO {
    @ApiModelProperty("总条数")
    private long totalNum;
    @ApiModelProperty("当前页码")
    private long currentPageNum;
    @ApiModelProperty("总页码")
    private long totalPages;
    @ApiModelProperty("是否有上一页")
    private  boolean hasPrevious;
    @ApiModelProperty("是否有下一页")
    private boolean hasNext;

    public static Builder builder()
    {
        return new Builder();
    }

    public PageInfoVO(long totalNum, long currentPageNum, long totalPages, long size, boolean hasPrevious, boolean hasNext)
    {
        this.totalNum=totalNum;
        this.currentPageNum=currentPageNum;
        this.totalPages=totalPages;
        this.hasPrevious=hasPrevious;
        this.hasNext=hasNext;
    }


    public static class Builder{
        public Map<String,Object> autoWired(Page page,Object obj)
        {
            Map<String,Object> res=new HashMap<>();
            res.put("data",obj);
            res.put("pageInfo",new PageInfoVO(page.getTotal(),page.getCurrent(),page.getPages(),page.getSize(),page.hasPrevious(),page.hasNext()));
             return res;
        }
    }
}
